﻿//#region Copyright (c) 2008 plexBB Team
///*  Copyright (c) 2008 plexBB Team
// *  
// *  This file is free software: you may copy, redistribute and/or modify it  
// *  under the terms of the GNU General Public License as published by the  
// *  Free Software Foundation, either version 2 of the License, or (at your  
// *  option) any later version.  
// *  
// *  This file is distributed in the hope that it will be useful, but  
// *  WITHOUT ANY WARRANTY; without even the implied warranty of  
// *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  
// *  General Public License for more details.  
// *  
// *  You should have received a copy of the GNU General Public License  
// *  along with this program.  If not, see <http://www.gnu.org/licenses/>. 
// */
//#endregion

//using System;
//using System.Collections.Generic;
//using System.Web.UI;
//using System.Web.UI.WebControls;
//using PlexBB.ModuleModel;

//namespace PlexBB.Templates.Admin
//{
//    public abstract class AdminTemplateBase : ForumTemplate
//    {
//        protected override void CreateChildControls()
//        {
//            base.CreateChildControls();
//            _confirm = ForumTemplate.Create<Confirm>();
//            _confirm.Visible = false;
//            _confirm.YesClick += _confirm_YesClick;
//            _confirm.NoClick += _confirm_NoClick;
//            Controls.Add(_confirm);

//            _message = ForumTemplate.Create<Message>();
//            _message.Visible = false;
//            _message.BackToPrevClick += _message_BackToPrevClick;
//            Controls.Add(_message);
//        }

//        protected void SetYesNoList(ListControl control, bool value)
//        {
//            if (control != null)
//            {
//                control.SelectedIndex = -1;
//                control.Items.FindByValue(value ? "true" : "false").Selected = true;
//            }
//        }

//        #region Message
//        private Message _message;

//        protected void ShowMessage(string messageTitle, string messageText, bool success, bool showBackToPrev)
//        {
//            ShowOneControl(_message);
//            _message.MessageTitle = messageTitle;
//            _message.MessageText = messageText;
//            _message.Success = success;
//            _message.ShowBackToPrev = showBackToPrev;
//        }

//        protected void ShowMessage(string messageText, bool success, bool showBackToPrev)
//        {
//            ShowMessage(null, messageText, success, showBackToPrev);
//        }

//        protected void ShowMessage(string messageText, bool success)
//        {
//            ShowMessage(messageText, success, true);
//        }

//        protected void ShowMessage(string messageText)
//        {
//            ShowMessage(messageText, true);
//        }

//        private void _message_BackToPrevClick(object sender, EventArgs e)
//        {
//            HideOneControl(_message);
//            OnBackToPrevClick(EventArgs.Empty);
//        }

//        protected virtual void OnBackToPrevClick(EventArgs e)
//        {
//        }
//        #endregion

//        #region Confirm
//        private Confirm _confirm;

//        protected string ConfirmCommand
//        {
//            get { return (string)ViewState["ConfirmCommand"]; }
//            private set { ViewState["ConfirmCommand"] = value; }
//        }

//        protected object ConfirmArgument
//        {
//            get { return ViewState["ConfirmArgument"]; }
//            private set { ViewState["ConfirmArgument"] = value; }
//        }

//        protected void ShowConfirm(string messageTitle, string messageText, string confirmCommand, object confirmArgument)
//        {
//            ShowOneControl(_confirm);
//            _confirm.Visible = true;
//            _confirm.MessageTitle = messageTitle;
//            _confirm.MessageText = messageText;
//            ConfirmCommand = confirmCommand;
//            ConfirmArgument = confirmArgument;
//        }

//        protected void HideConfirm()
//        {
//            HideOneControl(_confirm);
//        }

//        private void _confirm_NoClick(object sender, EventArgs e)
//        {
//            ConfirmEventArgs args = new ConfirmEventArgs(ConfirmCommand, ConfirmArgument);
//            HideConfirm();
//            OnConfirmNoClick(args);
//        }

//        private void _confirm_YesClick(object sender, EventArgs e)
//        {
//            ConfirmEventArgs args = new ConfirmEventArgs(ConfirmCommand, ConfirmArgument);
//            HideConfirm();
//            OnConfirmYesClick(args);
//        }

//        protected virtual void OnConfirmNoClick(ConfirmEventArgs e)
//        {
//        }
//        protected virtual void OnConfirmYesClick(ConfirmEventArgs e)
//        {
//        }
//        #endregion

//        private void ShowOneControl(Control control)
//        {
//            if (ViewState["originalVisibleIndexes"] != null)
//            {
//                throw new InvalidOperationException();
//            }
//            List<int> originalVisibleIndexes = new List<int>();
//            for (int i = 0; i < Controls.Count; i++)
//            {
//                if (Controls[i].Visible && Controls[i] != control)
//                {
//                    originalVisibleIndexes.Add(i);
//                    Controls[i].Visible = false;
//                }
//            }

//            ViewState["originalVisibleIndexes"] = originalVisibleIndexes.ToArray();
//            control.Visible = true;
//        }

//        private void HideOneControl(Control control)
//        {
//            int[] originalVisibleIndexes = (int[])ViewState["originalVisibleIndexes"];
//            for (int i = 0; i < Controls.Count; i++)
//            {
//                Controls[i].Visible = Array.IndexOf(originalVisibleIndexes, i) != -1;
//            }
//            ViewState["originalVisibleIndexes"] = null;
//        }
//    }

//    public class ConfirmEventArgs : EventArgs
//    {
//        private readonly string _confirmCommand;
//        private readonly object _confirmArgument;

//        public ConfirmEventArgs(string confirmCommand, object confirmArgument)
//        {
//            _confirmCommand = confirmCommand;
//            _confirmArgument = confirmArgument;
//        }

//        public string ConfirmCommand
//        {
//            get { return _confirmCommand; }
//        }
//        public object ConfirmArgument
//        {
//            get { return _confirmArgument; }
//        }
//    }
//}
